package org.xdq.demo.api.security;

import lombok.val;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.xdq.demo.dto.RoleQueryDto;
import org.xdq.demo.page.PageParam;
import org.xdq.demo.service.security.RoleService;
import org.xdq.demo.vo.MenuVo;
import org.xdq.demo.vo.R;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/security/role")
public class RoleController {
    @Autowired
    private RoleService roleService;

    @GetMapping("")
    public R<Map<String,Object>> roleList(RoleQueryDto dto){
        Map<String, Object> rolePage = roleService.getRolePage(dto);
        return R.OK(rolePage);
    }

    @GetMapping("/menu")
    public R<List<MenuVo>> allMenuList(){
        List<MenuVo> menuVoList = roleService.getMenuVoList();
        return R.OK(menuVoList);
    }

    @PostMapping ("")
    public R<?> execAddRole(@RequestBody Map<String,Object> dto){
        roleService.addNewRole(dto);
        return R.OK();
    }

    @GetMapping("/menu/{ro_id}")
    public R<List<Integer>> roleMenuIdList(@PathVariable Integer ro_id){
        List<Integer> idList = roleService.getRoleMenuIdList(ro_id);
        return R.OK(idList);
    }

    @PutMapping("/menu")
    public R<?> setRoleModules(@RequestBody Map<String,Object> map){
        roleService.setRoleModules(map);
        return R.OK();
    }
}
